package com.mzy.linear_struct.代码随想录.回溯;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author: mizy3
 * @Date: 2024/08/15/下午10:52
 * @Description:
 */
public class Pro46全排列 {
    LinkedList<Integer> path = new LinkedList<Integer>();
    List<List<Integer>> ans = new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {

        backtracking(nums, nums.length, 0);

        return ans;
    }

    private void backtracking(int[] nums, int k, int startIndex) {
        // 递归终止条件
        if(path.size() == k){
            ans.add(new ArrayList<>(path));
            return;
        }

        // 单层循环逻辑
        for (int i = 0; i < nums.length; i++){
            path.add(nums[i]);
            backtracking(nums, k, 0);
            path.removeLast();
        }
    }
}
